package Thread;

/**
 * Created with IntelliJ IDEA.
 * Description: 线程安全学习代码示例1：修改共享数据和原子性
 */
public class ThreadDemo15 {
    public static int a = 0;
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread() {
            @Override
            public void run() {
                for(int i = 0; i < 50000; i++) {
                    a++;
                }
            }
        };
        Thread t2 = new Thread() {
            @Override
            public void run() {
                for(int i = 0; i < 50000; i++) {
                    a++;
                }
            }
        };
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(a);
    }
}
